<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .father {
        width: 200px;
        height: 200px;
        background-color: greenyellow;
      }
      .son {
        width: 100px;
        height: 100px;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- 
        .stop修饰符可以用于阻止事件冒泡
       -->
      <h2>事件处理2</h2>
      <div class="father" @click="fatherClick">
        <div class="son" v-on:click.stop="sonClick"></div>
      </div>

      <!-- 
        .prevent修饰符用于阻止浏览器的默认行为
       -->
      <form action="" @submit.prevent="onSubmit">
        <input type="text" />
        <input type="submit" />
      </form>

      <h3>按键修饰符</h3>
      <input type="text" v-on:keyup.enter="handleKeyup" />
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      Vue.createApp({
        data() {
          return {};
        },
        methods: {
          sonClick(e) {
            // 用原生的方式可以解决事件冒泡
            // e.stopPropagation();
            console.log("sonClick");
          },
          fatherClick() {
            console.log("fatherClick");
          },
          onSubmit() {
            console.log("onSubmit");
          },
          handleKeyup(e) {
            // if (e.keyCode === 13) {
            //   console.log(e.target.value);
            // }
            // if (e.key === "Enter") {
            //   console.log(e.target.value);
            // }
            console.log(e.target.value);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
